<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../../css/aui/aui.css" />
    <title>注册</title>
    <style>
        html,
        body {
            background: #fff;
        }

        #app {
            font-size: 0.7rem;
        }

        .zhucetitle {
            color: #0689FB;
            border-bottom: 1px solid #0689FB;
            text-align: center;
            font-size: 0.9rem;
        }

        .aui-checkbox {
            width: 0.8rem;
            height: 0.8rem;
            margin-top: 0.1rem;
        }

        .row_flex {
            display: flex;
            align-items: center;
        }

        .inp {
            border-bottom: 1px solid #eee;
            margin-top: 0.5rem;
        }

        .active {
            color: #0689FB;
        }

        .btn {
            background: #0689FB;
            width: 80%;
            height: 2rem;
            text-align: center;
            line-height: 2rem;
            color: #fff;
            margin: 2rem auto 0;
            border-radius: 0.2rem;
        }

        .get_code {
            width: 9.5rem;
            color: #0689FB;
            text-align: center;
            border: 1px solid #0689FB;
            border-radius: 0.2rem;
        }
    </style>
</head>

<body>
    <div id="app">
        <div style="position:relative;">
            <img src="../../image/img/denglu_bg.png" alt="">
            <div style="position:absolute;top:0;left:0;width:100%;">
                <div style="width:5rem;height:5rem;margin:4rem auto 0;overflow:hidden;padding:0.2rem;border:1px solid #fff;border-radius:50%;">
                    <img src="../../image/icon/logo2.png" alt="">
                </div>
            </div>
        </div>
        <div style="padding:1rem 2rem;">
            <div class="zhucetitle">注册</div>
            <div class='row_flex inp'>
                <img src="../../image/icon/denglu01.png" style="width:1.5rem;height:1.5rem;" alt="">
                <input type="text" id="user_tel" placeholder="请输入手机号码">
            </div>
            <div class='row_flex inp'>
                <img src="../../image/icon/denglu03.png" style="width:0.9rem;height:0.9rem;margin:0 0.3rem;" alt="">
                <input type="text" id="captcha" placeholder="请输入验证码">
                <div class="get_code" onclick="send_code(this)">获取验证码</div>
            </div>
            <div class='row_flex inp'>
                <img src="../../image/icon/denglu02.png" style="width:1.2rem;height:1.2rem;margin:0 0.2rem;" alt="">
                <input type="password" id="user_pass" placeholder="请输设置密码">
            </div>
            <div class='row_flex inp'>
                <img src="../../image/icon/denglu04.png" style="width:0.8rem;height:0.8rem;margin:0 0.4rem;" alt="">
                <input type="text" id="user_invite_code" placeholder="请输入邀请者邀请码（选填）">
            </div>

            <div class="btn" onclick="register()">注册</div>
        </div>
        <footer class="row_flex" style="justify-content:center;" @click="openWin('login')">已有账号，请登录</footer>
    </div>
</body>
<script src="../../script/api.js" charset="utf-8"></script>
<script src="../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../script/common/check.js" charset="utf-8"></script>
<script src="../../script/common/common.js" charset="utf-8"></script>
<script src="../../script/common/config.js" charset="utf-8"></script>
<script src="../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    apiready = function() {
        api.parseTapmode();

    }

    var vm = new Vue({
        el: "#app",
        data: {},
        methods: {
            openWin(name) {
                var winInfo = {
                    login: {
                        name: 'login',
                        url: './login.html'
                    }
                };
                open_w(winInfo[name].name, winInfo[name].url);
            },
        }
    });

    // 发送验证码
    function send_code(e) {
        var user_tel = $("#user_tel").val();

        if (!checkMobile(user_tel)) {
            $toast("请输入正确的手机号码");
            return false;
        }

        sendsmsRegister(user_tel);
        var s = 60;
        $(e).text(s + 's后重新获取');
        $(e).attr("onclick", "");
        var smstime = setInterval(function() {
            s--;
            $(e).text(s + 's后重新获取');
            if (s == 0) {
                clearInterval(smstime);
                $(e).text("获取验证码");
                $(e).attr("onclick", "send_code(this)");
            }
        }, 1000);
    }

    // 发送验证码请求
    function sendsmsRegister(user_tel) {
        _ajax(Config.api.LoginSendsmsRegister, {
            user_tel: user_tel
        }, function(ret) {
            if (ret.code === 200) {
                $toast('发送成功');
            } else {
                $toast('发送失败');
            }
        });
    }

    // 注册
    function register() {
        var param = {
            user_tel: $("#user_tel").val(),
            user_pass: $("#user_pass").val(),
            captcha: $("#captcha").val(),
            user_invite_code: $("#user_invite_code").val(),
        }
        if (!is_define(param.user_tel)) {
            $toast("手机号不能为空");
            return;
        } else if (!checkMobile(param.user_tel)) {
            $toast("请输入正确的手机号码");
            return;
        } else if (!is_define(param.captcha)) {
            $toast("请输入验证码");
            return;
        } else if (param.captcha.length < 4) {
            $toast("验证码最少为4位");
            return;
        } else if (!is_define(param.user_pass)) {
            $toast("密码不能为空");
            return;
        } else if (param.user_pass.length < 6) {
            $toast("密码最少为6位");
            return;
        } else if (!is_define(param.user_invite_code)) {
            param.user_invite_code = 0;
        }
        _ajax(Config.api.LoginRegister, param, function(ret) {
            if (ret.code === 200) {
                $toast("注册成功");
                set_local("user_tel", param.user_tel);
                set_local("user_pass", param.user_pass);
                api.execScript({
                    name: 'login',
                    script: 'vm.init()'
                });
                setTimeout(function() {
                    vm.openWin('login');
                }, 1000);
            } else {
                $toast("注册失败");
            }
        });
    }
</script>

</html>
